<?php
$tokens = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx66f04c9622eb785f&secret=9d15671ea53ea2f40171ebc380f0254d");
$tokenArr = json_decode($tokens, true);

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

$accessToken = trim($tokenArr["access_token"]);
if( $accessToken != "") {
    echo "new token $accessToken, key gzh_access_token \n";
    $redis->setex("gzh_access_token", 7200, $accessToken) ;
}else {
    echo "do nothing \n";
    exit;
}

$jsTickets = file_get_contents("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=$accessToken&type=jsapi");
$jsTicketArr = json_decode($jsTickets, true);
$jsTicket = trim($jsTicketArr['ticket']);
if( $jsTicket != "") {
    echo "new js ticket $jsTicket key gzh_js_tikcet \n";
    $redis->setex("gzh_js_tikcet", 7200, $jsTicket );
}else {
    echo "do nothing\n";
    exit;
}
